<template>
 <div>
<el-breadcrumb separator-class="el-icon-arrow-right">
  <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
  <el-breadcrumb-item>文件操作</el-breadcrumb-item>
  <el-breadcrumb-item>批量添加题目</el-breadcrumb-item>
  
</el-breadcrumb>
<!--声明提示-->
<el-alert
    title="选择参数生成题库,点击下载或者回显"
    type="info"
    show-icon>
  </el-alert>
<el-card>
 <el-form :model="form" ref="FormRef" :rules="rules" label-width="70px">
  <el-form-item label="总分">
      <el-input
      oninput="value=value.replace(/^\.+|[^\d]/g,'')" 
      v-model="form.TotalScore"></el-input>
  </el-form-item>
  <el-form-item label="选择题数">
<el-input v-model="form.OptionNum"></el-input>
  </el-form-item>
  <el-form-item label="简答题数">
<el-input v-model="form.ShortAnswerNum"></el-input>
  </el-form-item>
<el-button type="primary" @click="GetExamlist">确 定</el-button>
  
  </el-form>
  <div v-if="showurldiv">
  <el-alert
    style="width:300px"
    title="点击这里可以使用识别码进行xls下载"
    type="info"
    show-icon>
  </el-alert>
  <el-input v-model="url" style="width:300px" >
  
  </el-input>
  <el-button type="primary" @click="DownLoad">点击下载
  </el-button>
  </div>
 


</el-card>

 </div>
</template>

<script>
//对外暴露接口
 export default {
name:'AutoExamList', 
   data () {
     return {
         form:{},
          rules: {
          TotalScore: [
            { required: true, message: '请输入分数', trigger: 'blur' },
           
          ],
          OptionNum: [
            { required: true, message: '请输入单选数量', trigger: 'blur' },
            
          ],
          ShortAnswerNum: [
            { required: true, message: '请输入简答数量', trigger: 'blur' },
           
          ],
          },
          url:"",
          showurldiv:false

     }
   },
   components: {

   },
   methods: {
       GetExamlist(){
           let that = this
           let url = "api/GenerateExamList"
           let data = {
               TotalScore:this.form.TotalScore,
               ShortAnswerNum:this.form.ShortAnswerNum,
               OptionNum:this.form.OptionNum,
           }
        this.$axios.post(url, this.$qs.stringify(data)).then(function(Response) {
        console.log(Response.data);
        let message = Response.data.message;
        let code = Response.data.code;
        let data = Response.data.data;
        if (code == 200) {
          that.$message.success(message);
          that.showurldiv = true;
          that.url=data
        
        } else {
          that.$message.error(message);
        
        }
      });

       },
       DownLoad(){
           window.open(this.url)
       }
   },
 }
</script>

<style scoped>

 
</style>
